/* getWavePars.c                             (\(\
 * Jannis Teunnissen and Florian Speelman    (='.')
 * Scientific Computing - spring 2010        o(_")")
 */

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <math.h>
#include "getWavePars.h"

void getWavePars(int argc, char *argv[], wavePars *p) {
    p->plucked = 0;
    p->fixedEnds = 0;
    p->nOutputs = 0;
    p->imgOutput = 0;
    p->loadBalance = 0;
    p->dx = 0.1;
    p->dt = 0.1;
    p->c = 1.;
    p->maxTime = 1.;
    p->sinPeriod = 1.;
    p->location = 0.5;
    p->amplitude = 0.1;
    
    int ch;
    while ((ch = getopt(argc, argv, "po:x:t:c:T:P:l:a:fgb")) != -1) {
        switch(ch) {
        case 'p': p->plucked = 1; break;
        case 'o': p->nOutputs = strtol(optarg, 0, 10); break;
        case 'x': p->dx = strtod(optarg, 0); break;
        case 't': p->dt = strtod(optarg, 0); break;
        case 'c': p->c = strtod(optarg, 0); break;
        case 'T': p->maxTime = strtod(optarg, 0); break;
        case 'P': p->sinPeriod = strtod(optarg, 0); break;
        case 'l': p->location = strtod(optarg, 0); break;
        case 'a': p->amplitude = strtod(optarg, 0); break;
        case 'f': p->fixedEnds = 1; break;
        case 'g': p->imgOutput = 1; break;
        case 'b': p->loadBalance = 1; break;
        }
    }
    p->totalPoints = (int) (round(1. / p->dx) + 1);
    
    printf("Parameters:\
            \n plucked (-p)     \t%d\
            \n fixedEnds (-f)   \t%d\
            \n nOutputs (-o)    \t%d\
            \n imgOutput (-g)   \t%d\
            \n loadBalance (-b) \t%d\
            \n dx (-x)          \t%.2e\
            \n dt (-t)          \t%.2e\
            \n c (-c)           \t%.2e\
            \n maxTime (-T)     \t%.2e\
            \n sinPeriod (-P)   \t%.2e\
            \n location (-l)    \t%.2e\
            \n amplitude (-a)   \t%.2e\n\n",
            p->plucked,
            p->fixedEnds,            
            p->nOutputs,
            p->imgOutput,
            p->loadBalance,          
            p->dx,
            p->dt,
            p->c,
            p->maxTime,
            p->sinPeriod,
            p->location,
            p->amplitude );
}
